#pragma once
#include "stmt.h"
#include "expr.h"

#include <stdio.h>
#include <string>
#include <list>

class PrintElement
{
public:
    PrintElement() { }
    virtual ~PrintElement() { }
    virtual void DoPrint() = 0;
};

class ExprElement: public PrintElement
{
public:
    ExprElement(Expr *_exp): expr(_exp) { }
    virtual ~ExprElement()
    {
        delete expr;
    }
    virtual void DoPrint()
    {
        if (expr->Type() == INT)
            printf("%d", expr->EvalInt());
        else if (expr->Type() == FLT)
            printf("%g", expr->EvalFlt());
    }
private:
    Expr *expr;
};

class StringElement: public PrintElement
{
public:
    StringElement(std::string _str): str(_str) { }
    virtual ~StringElement() { }

    virtual void DoPrint()
    {
        printf("%s", str.c_str());
    }
private:
    std::string str;
};


class Print :
    public Stmt
{
public:
    Print(int _ln);
    virtual ~Print(void);

    virtual int Eval();
    void AddString(std::string str);
    void AddExpr(Expr *expr);
    void AddSplit(char split);

private:
    std::list<PrintElement *> elements;
    std::list<char> splits;
};

